from multiprocessing import Process,Queue
from time import sleep

class MyProcess(Process):
    def __init__(self,name,mq):
        Process.__init__(self)
        self.name=name
        self.mq=mq
    def run(self):
        print(f'Process:{self.name},start')
        print(f'get data:{self.mq.get()}')
        sleep(2)
        self.mq.put(f'new_data:{self.name}')
        print(f'Process:{self.name},end')

if __name__=='__main__':
    p_list=[]
    mq=Queue()
    mq.put('1')
    mq.put('2')
    mq.put('3')
    #循环创建进程
    for i in range(3):
        p = MyProcess('p{}'.format(i),mq)
        p_list.append(p)
    for p in p_list:
        p.start()
    for p in p_list:
        p.join()

    print(mq.get())
    print(mq.get())
    print(mq.get())